﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using ElectronicWMSA.Comm.ClassFiles;
using SYDZ.WMS.DBUtility;

namespace ElectronicWMSA.Warehouse
{
    public partial class Frm_QianShu : Form
    {
        private string strWhere = " 1=1 ";
        public Frm_QianShu()
        {
            InitializeComponent();
            dtpTimeStart.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
        }
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewUserList.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewUserList.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
            if (rbWX.Checked)
            {
                this.strWhere = " 1=1 ";
                if (dtpTimeStart.Checked)
                {
                    strWhere += " and  ProDate >='" + dtpTimeStart.Text.Trim() + "'";
                }
                if (dtpTimeEnd.Checked)
                {
                    strWhere += " and  ProDate <='" + dtpTimeEnd.Text.Trim() + "'";
                }
                if (!string.IsNullOrEmpty(txt_KW.Text.Trim()))
                {
                    strWhere += "  and packinglistmain_no like '%" + txt_KW.Text.Trim() + "%'";
                }
                if (!string.IsNullOrEmpty(txt_Machine.Text.Trim()))
                {
                    strWhere += "  and Customer like '%" + txt_Machine.Text.Trim() + "%'";
                }
                GetData();
            }
            else
            {
                this.strWhere = " 1=1 ";
                if (dtpTimeStart.Checked)
                {
                    strWhere += " and  DeoSale_Str2 >='" + Convert.ToDateTime(dtpTimeStart.Text.Trim()).ToString("yyyyMMdd") + "'";
                }
                if (dtpTimeEnd.Checked)
                {
                    strWhere += " and  DeoSale_Str2 <='" + Convert.ToDateTime(dtpTimeEnd.Text.Trim()).ToString("yyyyMMdd") + "'";
                }
                if (!string.IsNullOrEmpty(txt_KW.Text.Trim()))
                {
                    strWhere += "  and  DeoSale_Number  like '%" + txt_KW.Text.Trim() + "%'";
                }
                if (!string.IsNullOrEmpty(txt_Machine.Text.Trim()))
                {
                    strWhere += "  and DeoSale_Machine like '%" + txt_Machine.Text.Trim() + "%'";
                }
                GetData1();
            }
        }

        #region
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }
        #endregion
        /// <summary>
        ///  导出
        /// </summary>
        private void btn_exct_Click(object sender, EventArgs e)
        {
            if (ddt.Rows.Count > 0)
            {
                ExPut.GetNopiExcel(ddt);
            }
            else
            {
                MessageBox.Show("请先查询");
            }


        }
        DataTable ddt = new DataTable();
        private void GetData()
        {
            IDataParameter[] parameters = new IDataParameter[]
                                        {
                                            new SqlParameter("@Tables",SqlDbType.NVarChar)
                                       };
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = strWhere;
            ddt = DbHelperSQL.RunProcedure("Pro_QIANSHU", parameters, "dtt").Tables[0];
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = ddt;
        }
        private void GetData1()
        {
            IDataParameter[] parameters = new IDataParameter[]
                                        {
                                            new SqlParameter("@Tables",SqlDbType.NVarChar)
                                       };
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = strWhere;
            ddt = DbHelperSQL.RunProcedure("Pro_WXQIANSHU", parameters, "dtt").Tables[0];
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = ddt;
        }
    }
}
